<?php
namespace app\api\controller;

use app\admin\model\ActiveCases;
use app\admin\model\IndexRotationPic;
use app\admin\model\ListContent;
use think\Controller;
use think\Request;

class Index extends Controller
{
    /**
     * @param Request $request
     * 首页轮播图
     */
    public function rotationList(Request $request)
    {
        $res = [];
        $data = $request->post();
        if(!isset($data['position'])){
            $res['status'] = 400;
            echo json_encode($res);die;
        }

        $where['position'] = $data['position'];
        $where['status'] = 1;
        $indexRotationPic = new IndexRotationPic();
        $rs = $indexRotationPic->getAll($where);
        if($rs == null){
            $res['data']['code'] = 0;
            $res['data']['msg'] = '获取失败';
        }else{
            $res['data']['code'] = 1;
            $res['data']['msg'] = '获取成功';
            $res['data']['list'] = $rs;
        }
        $res['status'] = 200;
        echo json_encode($res);
    }

    /**
     * @param Request $request
     * 首页精选
     */
    public function activeCaseList(Request $request)
    {
        $res = [];
        $data = $request->post();
        if(!isset($data['index_status'])){
            $res['status'] = 400;
            echo json_encode($res);die;
        }
        $activeCases = new ActiveCases();
        $rs = $activeCases->indexGetAll($data);

        if ($rs == null) {
            $res['data']['code'] = 0;
            $res['data']['msg'] = '获取失败';
        } else {
            $res['data']['code'] = 1;
            $res['data']['msg'] = '获取成功';
            $res['data']['list'] = $rs;
        }
        $res['status'] = 200;
        echo json_encode($res);
    }

    public function getSelectedList(Request $request)
    {
        $res = [];
        $data = $request->post();

        $listContent = new ListContent();
        $where['index_sort'] = ['neq',0];
        $rs = $listContent->getIndexList($where);

        if ($rs == null) {
            $res['data']['code'] = 0;
            $res['data']['msg'] = '获取失败';
        } else {
            $res['data']['code'] = 1;
            $res['data']['msg'] = '获取成功';
            $res['data']['list'] = $rs;
        }
        $res['status'] = 200;
        echo json_encode($res);
    }



}
